//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "personal_edit.h"
#include "datamodule.h"
#include "personal.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FIBDataSet"
#pragma link "pFIBDataSet"
#pragma resource "*.dfm"
TFormEditPersonal *FormEditPersonal;
bool SaveRecord=false;

//---------------------------------------------------------------------------
__fastcall TFormEditPersonal::TFormEditPersonal(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormEditPersonal::FormActivate(TObject *Sender)
{
 pFIBDataSetPedit->Close();
 pFIBDataSetPedit->ParamByName("Pid")->AsInteger = FormPersonal->id_personal;
 pFIBDataSetPedit->Open();
 pFIBDataSetLook->Open();
 if(pFIBDataSetPedit->RecordCount==0) pFIBDataSetPedit->Insert();
 else pFIBDataSetPedit->Edit();

}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::Button1Click(TObject *Sender)
{
try
{
 SaveRecord=true;
 DRIVER_CAT_A->Value=(CheckBoxA->Checked ?1:0);
 DRIVER_CAT_B->Value=(CheckBoxB->Checked ?1:0);
 DRIVER_CAT_C->Value=(CheckBoxC->Checked ?1:0);
 DRIVER_CAT_D->Value=(CheckBoxD->Checked ?1:0);
 DRIVER_CAT_E->Value=(CheckBoxE->Checked ?1:0);
 DRIVER_CAT_BE->Value=(CheckBoxBE->Checked ?1:0);
 DRIVER_CAT_CE->Value=(CheckBoxCE->Checked ?1:0);
 DRIVER_CAT_DE->Value=(CheckBoxDE->Checked ?1:0);
 pFIBDataSetPedit->Post();
}
catch(...)
{}
FormEditPersonal->Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::DBEditFChange(TObject *Sender)
{
 DBEditFIO->Text = DBEditF->Text +" "+DBEditI->Text+" "+DBEditO->Text;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::DBEditIChange(TObject *Sender)
{
 DBEditFIO->Text = DBEditF->Text +" "+DBEditI->Text+" "+DBEditO->Text;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::DBEditOChange(TObject *Sender)
{
 DBEditFIO->Text = DBEditF->Text +" "+DBEditI->Text+" "+DBEditO->Text;        
}
//---------------------------------------------------------------------------


void __fastcall TFormEditPersonal::Button2Click(TObject *Sender)
{
  FormEditPersonal->Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxAClick(TObject *Sender)
{
 //DRIVER_CAT_A->Value = 1-DRIVER_CAT_A->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::pFIBDataSetPeditCalcFields(
      TDataSet *DataSet)
{
if(!SaveRecord)
{
 CheckBoxA->Checked = (DRIVER_CAT_A->Value==0?false:true);
 CheckBoxB->Checked = (DRIVER_CAT_B->Value==0?false:true);
 CheckBoxC->Checked = (DRIVER_CAT_C->Value==0?false:true);
 CheckBoxD->Checked = (DRIVER_CAT_D->Value==0?false:true);
 CheckBoxE->Checked = (DRIVER_CAT_E->Value==0?false:true);
 CheckBoxBE->Checked = (DRIVER_CAT_BE->Value==0?false:true);
 CheckBoxCE->Checked = (DRIVER_CAT_CE->Value==0?false:true);
 CheckBoxDE->Checked = (DRIVER_CAT_DE->Value==0?false:true);
  if (pFIBDataSetPeditID_TYPE_PERSONAL->Value==3)
  {
 CheckBoxA->Enabled = true;
 CheckBoxB->Enabled = true;
 CheckBoxC->Enabled = true;
 CheckBoxD->Enabled = true;
 CheckBoxE->Enabled = true;
 CheckBoxBE->Enabled = true;
 CheckBoxCE->Enabled = true;
 CheckBoxDE->Enabled = true;
 DBEditDriverLic->Enabled=true;
 DBEditDriverLicDate->Enabled=true;
  }
  else
  {
 CheckBoxA->Enabled = false;
 CheckBoxB->Enabled = false;
 CheckBoxC->Enabled = false;
 CheckBoxD->Enabled = false;
 CheckBoxE->Enabled = false;
 CheckBoxBE->Enabled = false;
 CheckBoxCE->Enabled = false;
 CheckBoxDE->Enabled = false;
 DBEditDriverLic->Enabled=false;
 DBEditDriverLicDate->Enabled=false;
  }
 }
}
//---------------------------------------------------------------------------




void __fastcall TFormEditPersonal::CheckBoxBClick(TObject *Sender)
{
 //DRIVER_CAT_B->Value = 1-DRIVER_CAT_B->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxCClick(TObject *Sender)
{
 //DRIVER_CAT_C->Value = 1-DRIVER_CAT_C->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxDClick(TObject *Sender)
{
 //DRIVER_CAT_D->Value = 1-DRIVER_CAT_D->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxEClick(TObject *Sender)
{
 //DRIVER_CAT_E->Value = 1-DRIVER_CAT_E->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxBEClick(TObject *Sender)
{
 //DRIVER_CAT_BE->Value = 1-DRIVER_CAT_BE->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxCEClick(TObject *Sender)
{
  // DRIVER_CAT_CE->Value = 1-DRIVER_CAT_CE->Value;
}
//---------------------------------------------------------------------------

void __fastcall TFormEditPersonal::CheckBoxDEClick(TObject *Sender)
{
  // DRIVER_CAT_DE->Value = 1-DRIVER_CAT_DE->Value;        
}
//---------------------------------------------------------------------------


void __fastcall TFormEditPersonal::pFIBDataSetPeditID_TYPE_PERSONALChange(
      TField *Sender)
{
  if (pFIBDataSetPeditID_TYPE_PERSONAL->Value==3)
  {
 CheckBoxA->Enabled = true;
 CheckBoxB->Enabled = true;
 CheckBoxC->Enabled = true;
 CheckBoxD->Enabled = true;
 CheckBoxE->Enabled = true;
 CheckBoxBE->Enabled = true;
 CheckBoxCE->Enabled = true;
 CheckBoxDE->Enabled = true;
 DBEditDriverLic->Enabled=true;
 DBEditDriverLicDate->Enabled=true;
  }
  else
  {
 CheckBoxA->Enabled = false;
 CheckBoxB->Enabled = false;
 CheckBoxC->Enabled = false;
 CheckBoxD->Enabled = false;
 CheckBoxE->Enabled = false;
 CheckBoxBE->Enabled = false;
 CheckBoxCE->Enabled = false;
 CheckBoxDE->Enabled = false;
 DBEditDriverLic->Enabled=false;
 DBEditDriverLicDate->Enabled=false;
  }
}
//---------------------------------------------------------------------------

